package com.sz.jinzheng.service.impl;

import com.sz.jinzheng.mapper.BorrowInfoMapper;
import com.sz.jinzheng.mapper.BorrowerInfoMapper;
import com.sz.jinzheng.mapper.TaskMapper;
import com.sz.jinzheng.model.BorrowerInfo;
import com.sz.jinzheng.model.Task;
import com.sz.jinzheng.service.BorrowerInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Slf4j
@Service
public class BorrowerInfoServiceImpl implements BorrowerInfoService {
    @Resource
    private BorrowerInfoMapper borrowerInfoMapper;
    @Resource
    private BorrowInfoMapper borrowInfoMapper;
    @Resource
    private TaskMapper taskMapper;

    //开启事务
    @Transactional
    @Override
    public int addBorrowerInfo(BorrowerInfo borrowerInfo) {
        int i = borrowerInfoMapper.addBorrowerInfo(borrowerInfo);
        //如果添加成功 则创建对应的任务id
        int i1 = 0;
        if (i > 0) {
            Integer id = borrowerInfo.getId();
            log.info("id=" + id);
            i1 = taskMapper.addTask(new Task(id));
        }
        return i1;
    }


}
